package car.aistar.controller;

import car.aistar.bo.LaoxuDealBo;
import car.aistar.dto.XrbRecent;
import car.aistar.entity.CarBrands;
import car.aistar.entity.CarStyle;
import car.aistar.service.CarBrandsService;
import car.aistar.service.CarOverviewService;
import car.aistar.service.CarStyleService;
import car.aistar.service.DealCarService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ClassName NewDealXuController
 * @Description TODO 条件筛选后展示的成交车辆
 * @Author laoxu
 * @Date 2020/10/4 16:21
 * Version 1.0
 **/

@Controller
@RequestMapping("/newDeal")
public class NewDealXuController {
    @Autowired
    private DealCarService dealCarService;

    @Autowired
    private CarOverviewService carOverviewService;

    @Autowired
    private CarBrandsService carBrandsService;

    @Autowired
    private CarStyleService carStyleService;

    @RequestMapping("show")
    public String  newDealShow(Model model, String pageNow, String pageSize, LaoxuDealBo laoxuDealBo){
        Long br = Long.valueOf(laoxuDealBo.getBrName());
        Long st = Long.valueOf(laoxuDealBo.getStName());
        CarBrands carBrands = carBrandsService.queryById(br);
        String brName = carBrands.getBrName();
        CarStyle carStyle = carStyleService.queryById(st);
        String stName = carStyle.getStName();
        //模拟传入的参数
//        String brName = "大众";
//        String stName = "凌度";
//        String year = "2020";
//        String month = "09";
        List<XrbRecent> xrbRecentList = dealCarService.queryDealCar(brName,stName,laoxuDealBo.getYear(),laoxuDealBo.getMonth());
        model.addAttribute("newRecentList",xrbRecentList);
        pageNow = pageNow==null?"1":pageNow;
        if(pageSize == null  || "-1".equals(pageSize)){
            pageSize = "5";
        }
        PageInfo<XrbRecent> xrbRecentPageInfo= dealCarService.dealCarPage(laoxuDealBo.getBrName(),laoxuDealBo.getStName(),laoxuDealBo.getYear(),laoxuDealBo.getMonth(),pageNow,pageSize);
        model.addAttribute("page",xrbRecentPageInfo);
        return "sellCar/filter";
    }
}
